<script type="text/javascript">
    $(function() {
        $.fn.dataGridOptions.formSubFun("#form",'/coupon/doModify.html',"修改成功！","修改失败！");
        function checkdate()
        {   
            //获取系统时间
            var now = new Date(),str='';
            str += now.getFullYear();
            str += ("0" + (now.getMonth() + 1)).slice(-2);
            str += ("0" + now.getDate()).slice(-2); 
            str += ("0" + now.getHours()).slice(-2); 
            str += ("0" + now.getMinutes()).slice(-2); 
            str += ("0" + now.getSeconds()).slice(-2); 
            str = parseInt(str); 
            //获取开始时间
            var sTime = parseInt($('#startTime').val().replace(/[^0-9]/g,""));
            //比较系统时间和开始时间大小
            if(str >= sTime)
            {
                $('.timeLimit').attr('disabled',true);
            }
            else if(str < sTime)
            {
                $('.timeLimit').attr('disabled',false);
            }
        }
        checkdate();
    });
</script> 
<form id="form"  method="post">
<div class="popForm sForm">
    <input type="hidden" name="category" id="category" value="${coupon.category}">
    <input type="hidden" name="id" value="${coupon.id}">
    
    <div class="formitm">
        <label class="lab">名称：</label>
        <div class="ipt"><input class="timeLimit" type="text" id="categoryName" name="name" class="easyui-validatebox validatebox-text" data-options="required: true" value="${coupon.name}"></div>
    </div>
    <div class="formitm">
        <label class="lab">种类：</label>
        <div class="ipt">
            <select name="code" id="type" class="timeLimit">
                <option value="1">用户注册</option>
                <option value="2">实名认证</option>
                <!-- <option value="3">充值</option><option value="4">投资</option> -->
                <option value="5">邀请好友</option>
                <option value="6">VIP升级</option>
                <option value="7">首次充值</option>
                <option value="8">首次投资</option>
                
            </select>
        </div>
    </div>
    <div class="formitm">
        <label class="lab">启用：</label>
        <div class="ipt"><input type="radio" name="status" value="1"  <#if coupon.status==1>checked="checked"</#if>/>是&nbsp;&nbsp;&nbsp;<input type="radio" name="status" value="2" <#if coupon.status==2>checked="checked"</#if>/>否</div>
        
    </div>
    <div class="formitm">
        <label class="lab">发放时间：</label>
        <div class="ipt"><input type="text" name="putStartTime" id="startTime" style="width:140px;" class="easyui-validatebox timeLimit" data-options="required: true" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')}',readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="起始时间"   class="searchTime" value="${coupon.putStartTime?string('yyyy-MM-dd HH:mm:ss')}"/>-
        <input type="text" name="putEndTime" id="endTime" style="width:140px;" class="easyui-validatebox timeLimit" data-options="required: true" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}',readOnly:true})" placeholder="结束时间"  class="searchTime" value="${coupon.putEndTime?string('yyyy-MM-dd HH:mm:ss')}"/></div>
    </div>
    <div class="formitm">
        <label class="lab">有效期：</label>
        <div class="ipt"><input type="text" class="easyui-validatebox timeLimit" data-options="required: true,validType:'numOnly'" name="lifecycle" style="width:60px;" value="30" value="${coupon.lifecycle}">天</div>
    </div>
     <div class="formitm" id="redPacketMoney">
        <label class="lab"><#if coupon.category==1>比例<#else>金额</#if></label>
        <div class="ipt"><input type="text" class="easyui-validatebox validatebox-text timeLimit" name="denomination" id="denomination" value="${coupon.denomination}"style="width:60px;" data-options="required: true,validType:'numOnly'">元</div>
    </div>
    <div class="formitm" id="rules" style="display:none;">
        <label class="lab">&nbsp;</label>
        <div class="ipt" id="ruleList">
            <#list couponRules as item>
                <div class="ruleList"><input type="text" name="couponRules[${item_index}].minValue" value="${item.minValue}" style="width:60px;">≤投标/充值金额&lt;
                <input type="text" name="couponRules[${item_index}].maxValue" value="${item.maxValue}"  style="width:60px;">时，<#if coupon.category==1>比例<#else>金额</#if>
                <input type="text" name="couponRules[${item_index}].maxCount" value="${item.maxCount}"  style="width:60px;">元<a href="javascript:;" class="delRules">删除</a><a href="javascript:;" id="addRules">添加</a></div>
            </#list>
        </div>
    </div>
    
   
    
    
</div>
<script type="text/javascript">
    $(function() {
       $("#type").val("${coupon.code}");
       
       if ("${coupon.code}"==3 || "${coupon.code}"==4 || "${coupon.code}"==7 || "${coupon.code}"==8){
            $("#rules").show();
            $("#redPacketMoney").hide();
       }else{
        $("#rules").hide();
        $("#redPacketMoney").show();
    }
       
    });
    
    $("#type").change(function(){
        typeVal=$(this).val();
        if(typeVal==3 || typeVal == 4|| typeVal==7 || typeVal == 8){
            $("#rules").show();
            $("#denomination").val("0");
            $("#redPacketMoney").hide();
        }else{
            $("#rules").hide();
            $("#redPacketMoney").show();
        }
    })
    
    var count =${couponRules?size};
    $("#addRules").click(function(){
        var html="";
        html = '<div class="ruleList"><input type="text" name="couponRules['+count+'].minValue" style="width:60px;">≤投标/充值金额&lt;<input type="text" name="couponRules['+count+'].maxValue" style="width:60px;">时，红包金额<input type="text" name="couponRules['+count+'].maxCount" style="width:60px;">元<a href="javascript:;" class="delRules">删除</a></div>';
        $("#ruleList").append(html);
        count = count + 1;
    })
    
    //--------------------------------删除-------------------
    $("body").on("click",".delRules",function(){
        if($(".ruleList").length  > 1){
            $(this).parent().remove();
        }
    })
    
</script>
</form>
